#!/usr/bin/env python3
# main.py

import sys
import logging
import argparse
from PyQt6.QtWidgets import QApplication
from config import Config, CONFIG_FILE
from ui import DemucsGUI


def setup_logging():
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s - %(levelname)s - %(message)s"
    )


def main():
    setup_logging()

    parser = argparse.ArgumentParser(description="Demucs GUI wrapper")
    parser.add_argument("input_file", nargs="?", help="Audio file to process")
    parser.add_argument(
        "--format", "-f", help="Output format (e.g., wav, mp3, flac)")
    parser.add_argument("--no-gui", action="store_true",
                        help="Only print configuration without launching GUI")
    args = parser.parse_args()

    config = Config(CONFIG_FILE, cli_args=args)

    logging.info(f"Loaded config from {CONFIG_FILE}")
    logging.info(f"Config content: {config}")

    if args.no_gui:
        print("Configuration loaded:")
        print(config)
        return

    app = QApplication(sys.argv)
    gui = DemucsGUI(config)
    gui.resize(400, 150)
    gui.show()
    sys.exit(app.exec())


if __name__ == "__main__":
    main()
